window.onload = function () {
    document.getElementById("news-administration").className = "add_class";
    document.getElementById("inform").className = "add-nav-active";
};


// 图片上传
function Upload_img() {
    var form = new FormData();
    var files = document.getElementById("myfile").files[0];
    form.append("file", files);

    var xhr = new XMLHttpRequest();
    var local_host = window.location.host;          // 获取当前IP
    xhr.open('post', "/announcements/upload_imgs", true);
    xhr.send(form);
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
            if (xhr.status === 200) {
                document.getElementById("loading").style.display = "none";
                var JsonDate = JSON.parse(xhr.responseText);
                document.getElementById("cover-size").src = JsonDate["data"][0]["img-url"];
                document.getElementById("cover-img").style.display = "block";
            }
        }
    };
}


// 上传附件
function upload_accessory() {
    var form = new FormData();
    var files = document.getElementById("accessory").files[0];
    form.append("file", files);

    var xhr = new XMLHttpRequest();
    var local_host = window.location.host;          // 获取当前IP
    xhr.open('post', "/announcements/upload_accessory", true);
    xhr.send(form);
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
            if (xhr.status === 200) {
                document.getElementById("loading").style.display = "none";
                var JsonDate = JSON.parse(xhr.responseText);
                creat_table(JsonDate["data"][0])
            }
        }
    };
}


// 创建附件列表
function creat_table(JsonData) {
    var t_table = document.getElementById("t_table");
    var tr = document.createElement("tr");

    var td = document.createElement("td");var td1 = document.createElement("td");var td2 = document.createElement("td");var td3 = document.createElement("td");var td4 = document.createElement("td");var td5 = document.createElement("td");var td6 = document.createElement("td");
    td.innerHTML = "<input id='"+JsonData["accessory_name"]+"' class='check_box' type=\"checkbox\">";td.style.textAlign = "center";
    td1.innerHTML = t_table.children.length+1;td1.style.textAlign = "center";
    td2.innerHTML = JsonData["accessory_name"];td2.style.paddingLeft = "1%";
    td3.innerHTML = JsonData["file_size"];td3.style.paddingLeft = "1%";
    td4.innerHTML = JsonData["upload_time"];td4.style.textAlign = "center";
    td5.innerHTML = "";
    var local_host = window.location.host;
    td6.innerHTML = "<a href='"+"/announcements/file_download?file_path=" + JsonData["accessory_url"] + "'>下载</a>";td6.style.textAlign = "center";
    tr.appendChild(td);tr.appendChild(td1);tr.appendChild(td2);tr.appendChild(td3);tr.appendChild(td4);tr.appendChild(td5);tr.appendChild(td6);
    t_table.appendChild(tr);
}



// 获取新建新闻内容
function car_use_content() {
    document.getElementById("loading").style.display = "inline-block";
    // var editor_html = editor.txt.html().replaceAll("&", "%26");                // 富文本内容
    var car_license_plate = document.getElementById("car_license_plate").value;         // 新闻名称
    var start_time = document.getElementById("start_time").value;                //公告日期
    var end_time = document.getElementById("end_time").value;                //公告日期

    var sent_json = {};
    sent_json["car_license_plate"] = String(car_license_plate);
    sent_json["start_time"] = String(start_time);
    sent_json["end_time"] = String(end_time);

    var xhr = new XMLHttpRequest();
    var local_host = window.location.host;          // 获取当前IP
    xhr.open('post', "/administrative/add_cars_use.html", true);
    xhr.send(JSON.stringify(sent_json));
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
            if (xhr.status === 200) {
                document.getElementById("loading").style.display = "none";
                var json_data = JSON.parse(xhr.responseText);
                alert(json_data['message'])
            }
        }
    };
}


function Confirm_Preview() {
    var newWindow = window.open("Preview.html", "Preview.html");
    var form = document.createElement("form");
}
